package com.bynk.bynk_demo.controller;

import com.bynk.bynk_demo.common.result.Result;
import com.bynk.bynk_demo.dto.LoginDto;
import com.bynk.bynk_demo.dto.TestDto;
import com.bynk.bynk_demo.service.LoginService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;

//@Controller

@RestController
@RequestMapping("bynd")
public class HelloWorldController {

//    @Autowired
//    private LoginService loginService;

    //https://baidu.com:8080/search?s="muzhudechanhuaidjuh"
    @RequestMapping("/helloworld")
//    @ResponseBody// 以便于返回纯数据
    public String helloWorld(){
        return "hello world";
    }

    @GetMapping("/hello/{name}")
//    @ResponseBody// 以便于返回纯数据
    public String helloSomeone(@PathVariable("name") String name){
        return "hello world"+name;
    }

    @RequestMapping("/hellopage")
    public TestDto helloPage(){
        return new TestDto(100,"hhh","20231116");
    }


//    @RequestMapping (value = "/helloname",method = RequestMethod.POST)
//    public Result helloWorld(LoginDto loginDto){
//
//        return loginService.login(loginDto);
//    }

    @RequestMapping (value = "/hellologin",method = RequestMethod.POST)
    public String helloWorld(String name, String pwd, HttpServletRequest request, HttpServletResponse response) throws IOException {


        if (null==name||null==pwd)
            return "不能为空";

        if (name.equals("wwh")&&pwd.equals("123456"))
            return "登录成功,欢迎您wwh!";

        response.sendRedirect("html/login.html");
        return "登录失败";
    }
}
